let addAddressForm = new Vue({
    el:'#addAddressForm',
    data:{
        zoneActive:"1",
        provinceNames:[],
        cityNames:[],
        zoneNames:[],
        provinceVo:{},
        provinceActive:"1",
        cityVo:{},
        cityActive:"1",
        zoneVo:{},
        provinceName:'',
        cityName:'',
        zoneName:'',
        street:'',
        postcode:'',
        customerName: '',
        phone:'',
        status:'',
        hasError: false
    },
    methods:{
        addAddress:function () {
            console.log('Submit');
            console.log(this.provinceActive);
            let form=new FormData();
            form.append("provinceName",this.provinceActive);
            form.append("cityName",this.cityActive);
            form.append("zoneName",this.zoneActive);
            form.append("street",this.street);
            form.append("postcode",this.postcode);
            form.append("customerName",this.customerName);
            form.append("phone",this.phone);
            form.append("status",this.status);
            console.log(form);
            axios({
                method:'post',
                url:'/registerAddress',
                data:form
            })
                .then(function(r) {
                    console.log("|"+r.status+"|"+OK+"|");
                    if(r.data=="yes"){
                        console.log("地址添加成功");
                        console.log(r.data);
                        addAddressForm.hasError = false;
                        location.href = '/address.html';
                    }else{

                        console.log(r.data);
                        addAddressForm.hasError = true;
                        addAddressForm.message = r.data;
                    }
                });
        },
        getProvinceNames:function () {
            axios({
                url:"/portal/province",
                method:"get"
            }).then(function (response) {
                addAddressForm.provinceVo=response.data;

            })
        },
        getCityNames:function (event) {
            console.log(event)
            // let index=obj.selectedIndex;
            this.provinceActive=event.target.value;
            axios({
                url:"/portal/"+this.provinceActive+"/city",
                method: "get"
            }).then(function (response) {
                addAddressForm.cityVo=response.data;
            })
            this.$options.methods.getProvinceNames();
        },
        getZoneNames:function (event) {
            this.cityActive=event.target.value;
            axios({
                url:"/portal/"+this.cityActive+"/zone",
                method:"get"
            }).then(function (response) {
                addAddressForm.zoneVo=response.data;
            })
        },
        showZoneNames:function (event) {
            this.zoneActive=event.target.value;
        }
    },
    created:function () {
        this.getProvinceNames();
    }
});